package lastfm 
{
	import asunit.framework.TestCase;
  import lastfm.Autocompleter;
  import lastfm.events.AutocompleterEvent;
	
	/**
   * ...
   * @author Roman Marchenko
   */
  public class TestAutocompleter extends TestCase 
  {
    
    public function TestAutocompleter(testMethod:String = null) 
    {
      super(testMethod);
			
    }
    
    public function testAutocompleterArtist (): void
    {
      var handler: Function = function (event: AutocompleterEvent): void
      {
        assertNotNull(event.result);
        assertNotNull(event.result.suggestions);
        assertTrue(0 < event.result.suggestions.length);
        assertEquals("Nirvana", event.result.suggestions.source[0].artist);
      }
      
      var engine: Autocompleter = new Autocompleter(Autocompleter.TYPE_ARTIST);
      engine.addEventListener(AutocompleterEvent.SEARCH_RESULT, addAsync(handler, 10000));
      engine.search("ni");
    }

    public function testAutocompleterArtist2 (): void
    {
      var handler: Function = function (event: AutocompleterEvent): void
      {
        assertNotNull(event.result);
        assertNotNull(event.result.suggestions);
        assertTrue(0 < event.result.suggestions.length);
        assertEquals("Guano Apes", event.result.suggestions.source[0].artist);
      }
      
      var engine: Autocompleter = new Autocompleter(Autocompleter.TYPE_ARTIST);
      engine.addEventListener(AutocompleterEvent.SEARCH_RESULT, addAsync(handler, 10000));
      engine.search("guano");
    }

    public function testAutocompleterArtistCyr (): void
    {
      var handler: Function = function (event: AutocompleterEvent): void
      {
        assertNotNull(event.result);
        assertNotNull(event.result.suggestions);
        assertTrue(0 < event.result.suggestions.length);
        assertEquals("Чиж & Co", event.result.suggestions.source[0].artist);
      }
      
      var engine: Autocompleter = new Autocompleter(Autocompleter.TYPE_ARTIST);
      engine.addEventListener(AutocompleterEvent.SEARCH_RESULT, addAsync(handler, 10000));
      engine.search("чиЖ");
    }

    public function testAutocompleterArtistCyr2 (): void
    {
      var handler: Function = function (event: AutocompleterEvent): void
      {
        assertNotNull(event.result);
        assertNotNull(event.result.suggestions);
        assertTrue(0 < event.result.suggestions.length);
        assertEquals("ДДТ", event.result.suggestions.source[0].artist);
      }
      
      var engine: Autocompleter = new Autocompleter(Autocompleter.TYPE_ARTIST);
      engine.addEventListener(AutocompleterEvent.SEARCH_RESULT, addAsync(handler, 10000));
      engine.search("ддт");
    }
  }

}